package services;

import domain.entities.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Guillermo
 * Date: 12/09/12
 * Time: 12:01
 * To change this template use File | Settings | File Templates.
 */
@Service
public class ProtocolLevelDocumentationCategoryService {

    private ProtocolLevelDocumentationCategoryDAO protocolLevelDocumentationCategoryDAO;

    public ProtocolLevelDocumentationCategoryService() {
    }

    @Autowired
    public ProtocolLevelDocumentationCategoryService(ProtocolLevelDocumentationCategoryDAO protocolLevelDocumentationCategoryDAO) {
        this.protocolLevelDocumentationCategoryDAO = protocolLevelDocumentationCategoryDAO;
    }

    public List<ProtocolLevelDocumentationCategory> listAll(){
       return  protocolLevelDocumentationCategoryDAO.findAll();
    }

    public ProtocolLevelDocumentationCategory findById(Integer id){
        return protocolLevelDocumentationCategoryDAO.findById(id);
    }

    public ProtocolLevelDocumentationCategory findByDescripcion(String descripcion){
        return protocolLevelDocumentationCategoryDAO.findByDescripcion(descripcion);
    }

    public void checkCategory(String descripcion){
        if (!protocolLevelDocumentationCategoryDAO.existByDescripcion(descripcion)){
            protocolLevelDocumentationCategoryDAO.attachDirty(new ProtocolLevelDocumentationCategory(descripcion));
        }
        return ;
    }

}
